package com.java46.struts2.Food.service;


import com.java46.struts2.Food.dao.FoodDao;
import com.java46.struts2.base.entity.TDishesEntity;
import com.java46.struts2.base.exception.BusinessException;

import java.util.List;
/**
 * @ClassName FoodService
 * @Description 菜品的service
 * @Author Tigger Wu
 * @Date 2018/7/16 19:33
 * @Version 1.0
 **/
public class FoodService {
    private FoodDao foodDao = new FoodDao();

    /*
     *  查询全部菜品
     *
     * @author Tigger Wu
     * @date 2018/7/17 14:43
     * @param
     * @return
     */

    public List<TDishesEntity> queryAll(){
        List<TDishesEntity> slist = foodDao.queryAll();
        if(slist==null){
            return  null;
        }
        return slist;
    }
    /*
     *  添加菜品
     *
     * @author Tigger Wu
     * @date 2018/7/17 14:43
     * @param
     * @return
     */

    public  void addFood(TDishesEntity food){
        if(food==null){
            throw new BusinessException("没有任何信息添加");
        }
       foodDao.addFood(food);
    }

    /*
     *  删除菜品
     *
     * @author Tigger Wu
     * @date 2018/7/17 14:44
     * @param
     * @return
     */
    public  void removeFoods(int id){
        if("".equals(id)){
            throw new BusinessException("考虑下");
        }
        foodDao.removeFoods(id);
    }
/*
 *  修改菜品
 *
 * @author Tigger Wu
 * @date 2018/7/17 14:50
 * @param
 * @return
 */
    public void updateFoods(TDishesEntity foods){
        if(foods==null){
            throw new BusinessException("空的");
        }
        foodDao.updateFoods(foods);
    }
    /**
     *  查询类型下全部菜品
     *
     * @author TiggerWu
     * @date 2018/7/18  11:03
     * @param
     * @return
     */
    public Integer[] queryFoodsByTypeId(int id){
        if("".equals(id)){
            throw  new BusinessException("cc");
        }
        Integer[] arr = foodDao.queryFoodsId(id);
        return arr;
    }
    /**
     *  根据id查询菜品
     *
     * @author TiggerWu
     * @date 2018/7/18  17 :21
     * @param
     * @return
     */
    public List<TDishesEntity> querybyId(int id){
        if("".equals(id)){
            throw new BusinessException("g");
        }
        List<TDishesEntity> foods =  foodDao.queryById(id);
        return foods;
    }
}
